﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;
namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class PhieuTraHangNCCDAO
    {     
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion
        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion
        #region "Khai báo các Method"        
        public bool InsertPTHNCC(PhieuTraHangNCCDTO PhieuTraHangNCC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[10];
            par[0] = new SqlParameter("@MaTHNCC", PhieuTraHangNCC.MaTHNCC);
            par[1] = new SqlParameter("@MaNV", PhieuTraHangNCC.MaNV);
            par[2] = new SqlParameter("@MaKho", PhieuTraHangNCC.MaKho);
            par[3] = new SqlParameter("@MaNCC", PhieuTraHangNCC.MaNCC);
            par[4] = new SqlParameter("@MaSoThue", PhieuTraHangNCC.MaSoThue);
            par[5] = new SqlParameter("@NguoiTra", PhieuTraHangNCC.NguoiTra);
            par[6] = new SqlParameter("@NgayTra", PhieuTraHangNCC.NgayTra);
            par[7] = new SqlParameter("@ChungTuTra", PhieuTraHangNCC.ChungTuTra);
            par[8] = new SqlParameter("@GhiChuTH", PhieuTraHangNCC.GhiChuTH);
            par[9] = new SqlParameter("@TongThanhTien", PhieuTraHangNCC.TongThanhTien);            
            try
            {
                helper.InsertQuery("sp_Insert_PhieuTraHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdatePTHNCC(PhieuTraHangNCCDTO PhieuTraHangNCC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[10];
            par[0] = new SqlParameter("@MaTHNCC", PhieuTraHangNCC.MaTHNCC);
            par[1] = new SqlParameter("@MaNV", PhieuTraHangNCC.MaNV);
            par[2] = new SqlParameter("@MaKho", PhieuTraHangNCC.MaKho);
            par[3] = new SqlParameter("@MaNCC", PhieuTraHangNCC.MaNCC);
            par[4] = new SqlParameter("@MaSoThue", PhieuTraHangNCC.MaSoThue);
            par[5] = new SqlParameter("@NguoiTra", PhieuTraHangNCC.NguoiTra);
            par[6] = new SqlParameter("@NgayTra", PhieuTraHangNCC.NgayTra);
            par[7] = new SqlParameter("@ChungTuTra", PhieuTraHangNCC.ChungTuTra);
            par[8] = new SqlParameter("@GhiChuTH", PhieuTraHangNCC.GhiChuTH);
            par[9] = new SqlParameter("@TongThanhTien", PhieuTraHangNCC.TongThanhTien);            
            try
            {
                helper.UpdateQuery("sp_Update_PhieuTraHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeletePTHNCC(string MaTHNCC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@MaHDBS", MaTHNCC);
            try
            {
                helper.DeleteQuery("sp_Delete_PhieuTraHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_PhieuTraHangNCC()
        {
            helper = new Helper();
            DataSet ds_PTHNCC = helper.SelectQuery("sp_LayDS_PhieuTraHangNCC");
            return ds_PTHNCC;
        }
        #endregion
    }
}